package adv10;

import java.io.*;
import java.util.LinkedList;

public class FileSize {
	public static long getSize(File f) {
		if (f.isFile())
			return f.length();
		LinkedList<File> list = new LinkedList<File>();
		list.add(f);
		long len = 0;
		while (list.size() > 0) {
			File file = list.removeFirst();
			// len += file.length();
			File[] fr = file.listFiles();
			for (File t : fr) {
				if (t.isFile())
					len += t.length();
				else
					list.addLast(t);
			}
		}

		return len;
	}

	public static void main(String[] args) {
		long len = getSize(new File("E:\\资料"));
		System.out.println(len);
	}
}
